<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>填写地址</title>
		<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
		<meta content="yes" name="apple-mobile-web-app-capable" />
		<meta content="black" name="apple-mobile-web-app-status-bar-style" />
		<meta content="telephone=no" name="format-detection" />
		<link rel="stylesheet" href="css/ydui.css?rev=@@hash" />
		<link rel="stylesheet" href="css/demo.css" />
		<link rel="stylesheet" type="text/css" href="css/checkdemo.css" />
		<script src="js/address.js" type="text/javascript" charset="utf-8"></script>

		<!--必要样式-->
		<script src="js/ydui.flexible.js"></script>
	</head>

	<body>

		<section class="g-flexview">
			<section class="g-scrollview">
				<div class="m-celltitle">请填写收货地址</div>
				<div style="float: left;width: 100%;border-bottom:1px solid gainsboro ;">
					<div class="m-cell">
						<div class="cell-item">
							<div class="cell-left">所在地区：</div>
							<div class="cell-right cell-arrow">
								<input type="text" class="cell-input" readonly id="J_Address" placeholder="请选择收货地址">
							</div>
						</div>
					</div>
				</div>
				<div style="float: left;width: 100%;border-bottom:1px solid gainsboro ;height: 1rem;text-align: 1rem;">
					<p style="font-size: 0.3rem;float: left;padding-left: 0.24rem;margin-top: 0.25rem;">街道详情：</p>
					<input style="font-size: 0.3rem;border: 0px;padding-left: 0.1rem;margin-top: 0.25rem;" type="text" name="adress" id="adress" value="" placeholder="请填写街道详情" />
				</div>
				<div style="float: left;width: 100%;border-bottom:1px solid gainsboro ;height: 1rem;text-align: 1rem;">
					<p style="font-size: 0.3rem;float: left;padding-left: 0.24rem;margin-top: 0.25rem;">邮政编码：</p>
					<input style="font-size: 0.3rem;border: 0px;padding-left: 0.1rem;margin-top: 0.25rem;" type="number" name="zipCode" id="zipCode" value="" placeholder="请填写邮政编码" />
				</div>
				<div style="float: left;width: 100%;border-bottom:1px solid gainsboro ;height: 1rem;text-align: 1rem;">
					<p style="font-size: 0.3rem;float: left;padding-left: 0.24rem;margin-top: 0.25rem;">收件人名：</p>
					<input style="font-size: 0.3rem;border: 0px;padding-left: 0.1rem;margin-top: 0.25rem;" type="text" name="addressee" id="addressee" value="" placeholder="请填写收件人名称" />
				</div>
				<div style="float: left;width: 100%;border-bottom:1px solid gainsboro ;height: 1rem;text-align: 1rem;">
					<p style="font-size: 0.3rem;float: left;padding-left: 0.24rem;margin-top: 0.25rem;">联系号码：</p>
					<input style="font-size: 0.3rem;border: 0px;padding-left: 0.1rem;margin-top: 0.25rem;" type="number" name="phoneNumber" id="phoneNumber" value="" placeholder="请填写收件人号码" />
					
				</div>
				<!--<div style="margin-top: 15px;float: left;width: 100%;">
					<div class="opt" style="padding-left: 0.3rem;">
						<input class="magic-checkbox" type="checkbox" name="layout" id="c1">
						<label for="c1" style="font-size: 0.34rem;">是否设置为默认收件地址</label>
					</div>
				</div>-->
				<div style="margin-top: 2rem;float: left;width: 100%;">
					<div id="preservation" style="width: 50%;margin: auto;height: 1rem;background-color: royalblue;border-radius: 15px;text-align: center;line-height: 1rem;font-size: 0.34rem;color: white;">
						保存
					</div>
				</div>
			</section>
		</section>

		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="js/ydui.citys.js"></script>
		<script type="text/javascript" src="js/ydui.js"></script>
		<script type="text/javascript">
            function getUrlParam(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
                var r = window.location.search.substr(1).match(reg); //匹配目标参数
                if (r != null) return unescape(r[2]);
                return null; //返回参数值
            }
            /**
             * 默认调用
             */
            var provance;
            var city;
            var area;
            ! function() {
                var $target = $('#J_Address');
                $target.citySelect();
                $target.on('click', function(event) {
                    event.stopPropagation();
                    $target.citySelect('open');
                });
                $target.on('done.ydui.cityselect', function(ret) {
                    $(this).val(ret.provance + ' ' + ret.city + ' ' + ret.area);
                    //		alert(ret.provance + ' ' + ret.city + ' ' + ret.area);
                    provance = ret.provance;
                    city = ret.city;
                    area = ret.area;
                });
            }();
            var onlyId;
            var awardId;
            $(function() {
                onlyId = getUrlParam('onlyId');
                awardId = getUrlParam('awardId');
                $("#preservation").click(function() {
                    //						var selectCheckBox = $("#c1").is(":checked");
                    //						alert(selectCheckBox);
                    var adress = $("#adress").val();
                    var zipCode = $("#zipCode").val();
                    var addressee = $("#addressee").val();
                    var phoneNumber = $("#phoneNumber").val();
                    if (provance == null || city == null || area == null) {
                        alert("请仔细选择所在区域");
                        return;
                    }
                    if (adress == "" || adress.indexOf(" ") != -1) {
                        alert("请填写街道详情(不能包含空格)");
                        return;
                    }
                    if (zipCode == "" || adress.indexOf(" ") != -1) {
                        alert("请填写邮编地址(不能包含空格且只能为数字)");
                        return;
                    }
                    if (addressee == "" || adress.indexOf(" ") != -1) {
                        alert("请填写收件人名称(不能包含空格)");
                        return;
                    }
                    if (phoneNumber == "" || adress.indexOf(" ") != -1) {
                        alert("请填写手机号码(不能包含空格且只能为数字)");
                        return;
                    }
                    $.ajax({
                        type: "get",
                        url: http_open + "/foot/user/saveAddress?province=" + provance + "&city=" + city + "&district=" + area + "&address=" + adress + "&postCode=" + zipCode + "&name=" + addressee + "&phone=" + phoneNumber,
                        async: true,
                        success: function(req) {
                            if (req.error_code == 1) {
                                alert(req.data)
                                return;
                            }
                            alert("提交成功");
                            window.location.href = "selectAddress.html?addressId=" + req.data.id + "&id=" + onlyId + "&awardId=" + awardId;
                        },
                        error: function(req) {
                            alert(req);
                        }
                    });
                });
            })
		</script>

	</body>

</html>